import { getDistrict, getrvCd, getADMAAll, getWaterAssesment, getWaterLandmarhInfo, getEquipmentList, getOperationList, getAdma } from '@/api/district'
import { getFilterFieldOptions, getFilterNumValOptions } from "@/api/common.js";

const district = {
  state: {
    district: [],
    rivers: [],
    adma: [],
    assesment: [],
    waterLandInfos: [],
    EquipmentList: [],
    OperationList: [],
    adma_org: [],
    filterFieldOptions: [],
    filterNumValOptions: [],
  },

  mutations: {
    SET_DISTRICT: (state, district) => {
      state.district = district
    },
    SET_RIVERS: (state, rivers) => {
      state.rivers = rivers
    },
    SET_ADMA: (state, adma) => {
      state.adma = adma
    },
    SET_ASSESMENT: (state, assesment) => {
      state.assesment = assesment
    },
    SET_WATERLANDINFOS: (state, waterLandInfos) => {
      state.waterLandInfos = waterLandInfos
    },
    SET_EQUIPMENTLIST: (state, EquipmentList) => {
      state.EquipmentList = EquipmentList
    },
    SET_OPERATIONLIST: (state, OperationList) => {
      state.OperationList = OperationList
    },
    SET_ADMA_ORG: (state, data) => {
      state.adma_org = data
    },
    SET_FIELD_OPTIONS: (state, data) => {
      state.filterFieldOptions = data
    },
    SET_NUMVAL_OPTIONS: (state, data) => {
      state.filterNumValOptions = data
    },
  },

  actions: {
    // 获取行政区划
    getDistrict({ commit }) {
      return new Promise((resolve, reject) => {
        getDistrict().then(res => {
          commit('SET_DISTRICT', res.data)
          resolve(res)
        }).catch(error => {
          reject(error)
        })
      })
    },

    // 水功能区基本信息信息-所在河流
    async getRivers({ commit }) {
      let res = await getrvCd()
      commit('SET_RIVERS', res.data)
    },

    // 获取全部管理单位
    async getADMAAll({ commit }) {
      let res = await getADMAAll()
      commit('SET_ADMA', res.data)
    },

    // 水功能区基本信息信息-考核省份
    async getassesment({ commit }) {
      let res = await getWaterAssesment()
      commit('SET_ASSESMENT', res.data)
    },

    // 行政区界断面基本信息-河道断面
    async getWaterLandmarhInfos({ commit }) {
      let res = await getWaterLandmarhInfo()
      commit('SET_WATERLANDINFOS', res.data)
    },

    // 检测点列表查询-带分页
    async getEquipmentListS({ commit }) {
      let res = await getEquipmentList()
      commit('SET_EQUIPMENTLIST', res.data.list)
    },

    // 运维单位列表查询-不带分页
    async getOperationListS({ commit }) {
      let res = await getOperationList()
      commit('SET_OPERATIONLIST', res.data)
    },
    // 获取全部管理单位(编制单位) 
    async getADMAORG({ commit }) {
      let res = await getAdma()
      commit('SET_ADMA_ORG', res.data)
    },
    // 获取表格字段筛选选项
    getFieldOptions({ commit }) {
      Promise.all([
        getFilterFieldOptions(),
        getFilterNumValOptions()
      ]).then(resList => {
        let [filterFieldOptionsData, filterNumValOptionsData] = resList;
        // 字段选项
        if (filterFieldOptionsData.status == 200) {
          commit('SET_FIELD_OPTIONS', filterFieldOptionsData.data)
        }
        // 数值选项
        if (filterNumValOptionsData.status == 200) {
          commit('SET_NUMVAL_OPTIONS', filterNumValOptionsData.data)
        }
      })
    }
  }
}

export default district